#include "CommandManager.h"
#include "constants.h"

CommandManager::CommandManager(void)
{
}

CommandManager::~CommandManager(void)
{
}

void CommandManager::interpretCommand(string cmd)
{
	cmdType = CMD_LIST_END;
	string token="";
	token = cmd.substr(0, cmd.find_first_of(' '));
	if (strcmp(token.c_str(), "")==0)
	{
		token = cmd;
	}
	else
	{
		cmd = cmd.substr(cmd.find_first_of(' ')+1);
	}

	if (strcmp(token.c_str(), "cd")==0)
	{
		cmdType = CMD_CHANGE_DIR;
	}

	else if (strcmp(token.c_str(), "ls")==0)
	{
		cmdType = CMD_LIST_DIR;
	}

	else if (strcmp(token.c_str(), "mkdir")==0)
	{
		cmdType = CMD_MAKE_DIR;
	}

	else if (strcmp(token.c_str(), "md")==0)
	{
		cmdType = CMD_CHANGE_DIR;
	}

	if (strcmp(token.c_str(), "nf")==0)
	{
		cmdType = CMD_NEW_FILE;
	}

	if (strcmp(token.c_str(), "sw")==0)
	{
		cmdType = CMD_SHOW_FILE;
	}

	if (strcmp(token.c_str(), "exit")==0)
	{
		cmdType = CMD_EXIT;
	}
	executeCurrentCmd();
}

void CommandManager::executeCurrentCmd()
{
	switch (cmdType)
	{
	//command implementation
	case CMD_CHANGE_DIR:
	{
		printf("CMD_CHANGE_DIR implementation\n");
	}
		break;
	case CMD_MAKE_DIR:
	{
		printf("CMD_MAKE_DIR implementation\n");
	}
		break;
	case CMD_LIST_DIR:
	{
		printf("CMD_LIST_DIR implementation\n");
	}
		break;
	case CMD_SHOW_FILE:
	{
		printf("CMD_SHOW_FILE implementation\n");
	}
		break;
	case CMD_NEW_FILE:
	{
		printf("CMD_NEW_FILE implementation\n");
	}
		break;
	case CMD_EXIT:
	{
		printf("\nEXIT\n");
		exit(0);
	}
		break;
	default:
		printf("\nunkonw comand\n");
	}
}